﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--<title>自贸工服 | 数据同步平台</title>-->
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="~/plugins/fontawesome-free/css/all.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <!-- Tempusdominus Bbootstrap 4 -->
    <link rel="stylesheet" href="~/plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="~/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
    <!-- JQVMap -->
    <link rel="stylesheet" href="~/plugins/jqvmap/jqvmap.min.css">
    <!-- overlayScrollbars -->
    <link rel="stylesheet" href="~/plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
    <!-- summernote -->
    <link rel="stylesheet" href="~/plugins/summernote/summernote-bs4.css">
    <!-- SweetAlert2 -->
    <link rel="stylesheet" href="~/plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css">
    <!-- 自定义  style -->
    <link href="~/css/custom/global.css" rel="stylesheet" />

    <link href="~/img/fav.ico" rel="shortcut icon">
    @RenderSection("pagestyle", false)

    <!-- Theme style -->
    <link rel="stylesheet" href="~/css/adminlte.min.css">
</head>
<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">
        <!-- Navbar -->
        <nav class="main-header navbar navbar-expand navbar-white navbar-light">
            <!-- Left navbar links -->
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" data-widget="pushmenu" href="#"><i class="fas fa-bars"></i></a>
                </li>
                <li class="nav-item d-none d-sm-inline-block">
                    <a href="/home/" class="nav-link">首页</a>
                </li>
            </ul>

            <!-- SEARCH FORM -->
            <form class="form-inline ml-3" style="display:none;">
                <div class="input-group input-group-sm">
                    <input class="form-control form-control-navbar" type="search" placeholder="搜索内容" aria-label="搜索">
                    <div class="input-group-append">
                        <button class="btn btn-navbar" type="submit">
                            <i class="fas fa-search"></i>
                        </button>
                    </div>
                </div>
            </form>

            <!-- Right navbar links -->
            <ul class="navbar-nav ml-auto">
                <li class="nav-item dropdown">
                    <a class="nav-link" data-toggle="dropdown" href="#">
                        <i class="far fa-user"></i>
                    </a>
                    <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
                        <a href="javascript:profile()" class="dropdown-item">
                            <!-- Message Start -->
                            <div class="media">
                                <img id="avatar" src="~/img/user.jpg" alt="User Avatar" class="img-size-50 mr-3 img-circle">
                                <div class="media-body">
                                    <h3 id="h3UserName" style="font-size:1.5rem" class="dropdown-item-title">
                                    </h3>
                                    <p id="pUserRole" class="text-sm text-muted">管理员</p>
                                </div>
                            </div>
                            <!-- Message End -->
                        </a>
                        <div class="dropdown-divider"></div>
                        <a href="#" data-toggle="modal" data-target="#modal-default-logout" class="dropdown-item dropdown-footer">退出登录</a>
                    </div>
                </li>
            </ul>
        </nav>
        <!-- /.navbar -->
        <!-- Main Sidebar Container -->
        <aside class="main-sidebar sidebar-dark-primary elevation-4">
            <!-- Brand Logo -->
            <a href="/home/" class="brand-link">
                <img src="~/img/adminlogo.jpg" alt="自贸工服" class="brand-image img-circle elevation-3"
                     style="opacity: .8">
                <span class="brand-text font-weight-light">自贸工服</span>
            </a>

            <!-- Sidebar -->
            <div class="sidebar">
                <!-- Sidebar Menu -->
                <nav class="mt-2">
                    <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
                        <!-- Add icons to the links using the .nav-icon class with font-awesome or any other icon font library -->
                        <li class="nav-item has-treeview" name="home">
                            <a href="/home/" class="nav-link">
                                <i class="nav-icon fas fa-tachometer-alt"></i>
                                <p>
                                    概况
                                </p>
                            </a>
                        </li>
                        <li class="nav-item has-treeview" name="user">
                            <a href="#" class="nav-link">
                                <i class="nav-icon fas fa-user-friends"></i>
                                <p>
                                    内容
                                    <i class="fas fa-angle-left right"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="/admin/articleClasses" class="nav-link">
                                        <i class="fas fa-user nav-icon"></i>
                                        <p>内容分类</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="/admin/articles" class="nav-link">
                                        <i class="fas fa-user-tie nav-icon"></i>
                                        <p>内容管理</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="nav-item has-treeview" name="user">
                            <a href="#" class="nav-link">
                                <i class="nav-icon fas fa-user-friends"></i>
                                <p>
                                    新闻
                                    <i class="fas fa-angle-left right"></i>
                                </p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="/admin/articles?c=1" class="nav-link">
                                        <i class="fas fa-user-tie nav-icon"></i>
                                        <p>新闻管理</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="/admin/articles/addArticle?c=1" class="nav-link">
                                        <i class="fas fa-user-tie nav-icon"></i>
                                        <p>添加新闻</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </nav>
                <!-- /.sidebar-menu -->
            </div>
            <!-- /.sidebar -->
        </aside>

        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            @RenderBody()
        </div>
        <!-- /.content-wrapper -->
        <footer class="main-footer">
            &copy; 2022 <a href="/">沈阳自贸工业服务有限责任公司</a> All rights reserved.
            <div class="float-right d-none d-sm-inline-block">
                <b>Version</b>1.0
            </div>
        </footer>

        <!-- Control Sidebar -->
        <aside class="control-sidebar control-sidebar-dark">
            <!-- Control sidebar content goes here -->
        </aside>
        <!-- /.control-sidebar -->
        <!-- Modal -->
        <!-- top:calc(50% - (height/2 + 28px)) -->
        <div class="modal fade" id="modal-default-logout" style="top:calc(50% - 147px)">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">退出登录</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <p>确定要退出登录吗？</p>
                    </div>
                    <div class="modal-footer justify-content-between">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button id="btnLogout" type="submit" class="btn btn-primary">确定</button>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->
        <div class="modal fade" id="modal-default-confirm" style="top:calc(50% - 147px);">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 id="modal-confirm-title" class="modal-title">提示</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <p id="modal-confirm-message"></p>
                    </div>
                    <div class="modal-footer justify-content-between">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button id="modal-confirm-button-confirm" type="button" class="btn btn-primary">确定</button>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <div class="modal fade" id="modal-default-overlay" style="padding-right: 17px;padding-top:45vh">
            <div class="modal-dialog">
                <div class="overlay d-flex justify-content-center align-items-center">
                    <i class="fas fa-2x fa-sync fa-spin"></i>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>

        <div class="modal fade" id="modal-default-profile" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="top:calc(50% - 300px)">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">修改信息</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label>头像</label>
                            <div class="headbox">
                                <img id="imgavatar" src="/img/user.jpg" />
                                <input type="file" id="fileAvatar" accept="*.png,*.jpg,*.jpeg" toptip="" />
                            </div>
                        </div>
                        <div class="form-group col-9">
                            <label>用户名</label>
                            <input id="username" name="username" type="text" class="form-control" placeholder="用户名" readonly>
                        </div>
                        <div class="form-group col-9">
                            <label>原密码</label>
                            <input type="password" class="form-control" id="password" autocomplete="off" value="" />
                        </div>
                        <div class="form-group col-9">
                            <label>新密码</label>
                            <input type="password" class="form-control" id="newpassword" autocomplete="off" value="" />
                        </div>
                        <div class="form-group col-9">
                            <label>确认密码</label>
                            <input type="password" class="form-control" id="confirmpassword" autocomplete="off" value="" />
                        </div>
                    </div>
                    <div class="modal-footer justify-content-between">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button id="btnSubmitProfile" type="button" class="btn btn-primary">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- ./wrapper -->
    <!-- jQuery -->
    <script src="~/plugins/jquery/jquery.min.js"></script>
    <!-- jQuery UI 1.11.4 -->
    <script src="~/plugins/jquery-ui/jquery-ui.min.js"></script>

    <!-- Bootstrap 4 -->
    <script src="~/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
    <!-- overlayScrollbars -->
    <script src="~/plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
    <!-- SweetAlert2 -->
    <script src="~/plugins/sweetalert2/sweetalert2.min.js"></script>
    <!-- AdminLTE App -->
    <script src="~/js/adminlte.js"></script>
    <!-- 自定义 GLOBAL JS -->
    <script src="~/js/custom/global.js"></script>
    <script type="text/javascript">

        //Resolve conflict in jQuery UI tooltip with Bootstrap tooltip
        $.widget.bridge('uibutton', $.ui.button)
        $(document).ready(function () {
            var path = window.location.pathname;  //先得到地址栏内容
            path = path == "/" ? "/home/" : path;
            var regExp = /[\/\.\?]+/;
            str = path.split(regExp);
            var node = str.slice(-2, -1);   //截取地址栏信息得到文件名
            $(".nav-item.has-treeview[name='" + node[0] + "']").addClass("menu-open");
            $(".nav-item.has-treeview[name='" + node[0] + "'] a[href='#']").addClass("active");
            $(".nav-item.has-treeview a[href='" + path + "']").addClass("active");
            if (window.gp.user.Current() != null) {
                $("#h3UserName").text(window.gp.user.Current().UserName);
                $("#avatar").attr("src", window.gp.user.Current().Avatar);
            }


            $("#fileAvatar").on("change", function (e) {
                var reader = new FileReader();
                reader.readAsDataURL(e.target.files[0]);
                reader.onload = function (e) {
                    $("#imgavatar").attr("src", e.target.result);
                };
            });

            $("#btnSubmitProfile").on("click", function () {
                var profile = { UserName: $.trim($("#username").val()), Avatar: $("#imgavatar").attr("src"), Password: $.trim($("#password").val()), NewPassword: $.trim($("#newpassword").val()) };
                if (profile.Avatar == "/img/user.jpg" || $("#fileAvatar").val() == "" || $("#fileAvatar")[0].files.length == 0) {
                    profile.Avatar = "";
                }
                if (profile.NewPassword != null && profile.NewPassword.length > 0) {
                    if (profile.Password == null || profile.Password.length < 1) {
                        alert("请输入密码！");
                        return false;
                    }
                    if (profile.NewPassword != $("#confirmpassword").val()) {
                        alert("两次密码不一致！");
                        return false;
                    }
                }
                if (profile.Avatar.length > 0 || profile.NewPassword.length > 0) {
                    var actionUrl = "/account/profile";
                    $.ajax({
                        url: actionUrl,
                        data: JSON.stringify(profile),
                        type: 'post',
                        dataType: 'json',
                        contentType: "application/json",
                        async: true,
                        success: function (result) {
                            if (result.code == 200) {
                                if (result.data != null) {
                                    window.gp.user.Set({ UserName: result.data.name, Avatar: result.data.avatar });
                                }
                                alert("操作成功！");
                                setTimeout("window.location.reload()", 1000);
                            }
                            else {
                                alert(result.msg, "error");
                            }
                        },
                        error: function (msg) {
                            alert(msg.status + ":" + msg.statusText, "error");
                        }
                    });

                }
                else {
                    $("#modal-default-profile").modal("hide");
                }
            });
        })

        function profile() {
            $("#modal-default-profile input").val("");
            $("#username").val(gp.user.Current().UserName);
            $("#imgavatar").attr("src", gp.user.Current().Avatar);
            $("#modal-default-profile").modal();
        }
    </script>
    @RenderSection("pagescript", false)
</body>
</html>
